package com.driving.single.common.redis.service.impl;

import com.driving.single.common.redis.service.CommonRedisCoachClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Service
public class CommonRedisCoachClassesServiceImpl implements CommonRedisCoachClassesService {
    @Value("${redis_key_frontend_coach_classes}")
    private String redis_key_frontend_coach_classes;   // 教练详情-班级及费用KEY
    @Value("${redis_key_frontend_coach_expire_second}")
    private Integer redis_key_frontend_coach_expire_second;   // 教练详情KEY过期时间(单位：秒)

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    /**
     * 缓存教练详情-班级及费用
     * @param mapTbCoachClassesList 教练详情-班级及费用对象
     */
    @Override
    public Integer insertRedisCoachClasses(List<Map<String, Object>> mapTbCoachClassesList, Long coachId) {
        String key = this.redis_key_frontend_coach_classes + ":" + coachId;
        this.redisTemplate.opsForValue().set(key,mapTbCoachClassesList,this.redis_key_frontend_coach_expire_second, TimeUnit.SECONDS);
        return 200;
    }
    /**
     * 查询缓存中的教练详情-班级及费用
     * @param coachId 教练ID
     */
    @Override
    public List<Map<String, Object>> selectRedisTbCoachClassesByCoachId(Long coachId) {
        String key = this.redis_key_frontend_coach_classes + ":" + coachId;
        return (List<Map<String, Object>>) this.redisTemplate.opsForValue().get(key);
    }
}
